#include "EnemyObject.h"
#include "SpriteMaker.h"
#include "EnemyBody.h"
EnemyObject::EnemyObject(b2World *_World) :BaseObject(_World)
{
}

EnemyObject::~EnemyObject()
{
}

void EnemyObject::init(SpriteBatchNode* _Spritebatch, SpriteFrameCache* _Cache, Sprite *_Parent)
{
	mId = OBJECT_ENEMY;
	mIsAction = false;
	mIsCollision = false;

	mBody = new EnemyBody(mWorld, b2_dynamicBody);
	mBody->mColBody->SetUserData(this);
	mSprite = SpriteMaker::makeSprite(_Spritebatch, "gun_01.png");
	mSprite->setScaleX(0.5f);
	mAnimation = SpriteMaker::makeAnimation(_Cache, "gun", 1, 4, 1.f);
	mSprite->runAction(mAnimation);
}

void EnemyObject::update(float dt)
{
	draw();
}

void EnemyObject::draw()
{
	if (mIsAction == false)
	{
		mSprite->setPosition(Vec2(mBody->getPosition().x, mBody->getPosition().y));
		mSprite->setRotation(mBody->getAngle()*-Define::RAD_TO_DEG);
	}
	else
	{
		mBody->setPosition(b2Vec2(mSprite->getPosition().x, mSprite->getPosition().y));
		mBody->setAngle(mSprite->getRotation()*-Define::DEG_TO_RAD);
	}
}

void EnemyObject::destroy()
{
	
}

void EnemyObject::onCollisionWith(BaseObject *_Object)
{
}

void EnemyObject::initAction()
{
	mAction = NULL;
}

